<template>
	<view class="mainpadding" style="padding-bottom: 150rpx;">
		<view class="ffffff radius mainpadding">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
			</view>
			<view class="shangj" v-for="item in list.data" :key="item.id">
				<view class="xiahuaxian flexbetween ">
					<view class="touxiang">
						<image :src="item.avatar_text" mode=""></image>
					</view>
					<view class="" style="width: 84%;">
						<view class="flexbetween">
							<view class="flexleft">
								<view class="titletext xiaohei sanshier nofonweight margin_right3">{{item.username}}
								</view>
								<view class="strongtext xiaohei ershiba nofonweight">{{item.mobile}}</view>
							</view>
							<view class="lvbtn2" v-if="item.type==1">有效客户</view>
							<view class="huibtn" v-if="item.type==2">无效客户</view>
						</view>
						<view class="strongtext xiaohui ershiba nofonweight margin_top1 yhxk">地址：{{item.address}}</view>
					</view>
				</view>
				<view class="flexright margin_top2">
					<view class="baibtn margin_right2" @click="delitem(item.id)">移除</view>
					<view class="lvbtn margin_right2" @click="jumper('/pages_xiaoshou/xinzengkehu?id=',item.id)">编辑</view>
					<view class="huangbtn " @click="jumper('/pages_xiaoshou/genjinjl?id=',item.id)">跟进记录
					</view>
				</view>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="jumper('/pages_xiaoshou/xinzengkehu','')">新建客户</view>
		</view>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				modal:{
					modalShow:false,
					title:"是否确认删除当前客户？",
				},
				currentid:"",
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			delitem(id){
				this.modal.modalShow = true
				this.currentid = id
			},
			modalSure(){
				if(this.modal.title=="是否确认删除当前客户？"){
					httpRequest.request("/api/user/deleteCgKh", 'GET', {
						id:this.currentid
					}).then(res => {
						httpRequest.toast(res.msg)
						if(res.code==1){
							this.init()
						}
					})
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit
				}
				let url = '/api/user/cgKhIndex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
						this.$forceUpdate()
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			jumper(url, id) {
				uni.navigateTo({
					url: url + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.huangbtn {
		background-color: #ffa126;
		padding: 8rpx 20rpx;
		font-size: 24rpx;
		color: #fff;
		box-sizing: border-box;
		border-radius: 30rpx
	}

	.huibtn {
		width: 120rpx;
		height: 30rpx;
		background: #AAAAAA;
		border-radius: 4rpx 4rpx 4rpx 4rpx;
		font-size: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: normal;
		color: #FFFFFF;
	}

	.lvbtn2 {
		width: 120rpx;
		height: 30rpx;
		background: #1BA95B;
		border-radius: 4rpx 4rpx 4rpx 4rpx;
		font-size: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: normal;
		color: #FFFFFF;
	}

	.touxiang {
		width: 88rpx;
		height: 88rpx;
		border-radius: 50%;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}

	.shangj {
		margin-top: 30rpx;
	}

	.shangj:first-child {
		margin-top: 0rpx;
	}

	page {
		background-color: #F5F5F5;
	}
</style>